home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / pdisk.zip / FDINTINS.C < prev    next >
C/C++ Source or Header  |  1989-01-12  |  9KB  |  320 lines

  1. /* fdintins: Install the FDINTTBL program for various systems.  See assembly
  2.  * source code for fdtblint at the bottom of this file.
  3.  *
  4.  * Copyright (C) 1986, Scott E. Garfinkle.  All rights reserved.
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stddef.h>
  9.  
  10. typedef unsigned char byte;
  11. typedef unsigned int word;
  12. typedef unsigned long dword;
  13.  
  14. #include <fcntl.h>
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17. #include <io.h>
  18. #include <dos.h>
  19. #include <errno.h>
  20. #include <ctype.h>
  21.  
  22. #pragma pack(1)
  23.  
  24. typedef struct {        /* BIOS-maintained fixed disk parameter table entry.
  25.                  * INT 0x41 (or 46 for drive 2) points to a descriptor
  26.                  * table for the current fixed drive.  See BIOS listing
  27.                  */
  28.     word fd_ncyls;            /* number of cylinders on drive */
  29.     char fd_heads;            /* number of heads on drive */
  30.     word  fd_current;    /* starting cyl for reduced write current (XT only) */
  31.     word fd_write_precomp;    /* starting cylinder for write pre-compensation
  32.                              * or -1 if no write precompensation needed.
  33.                              */
  34.     byte fd_ecc_burst,    /* max ecc data burst length (XT only) */
  35.          fd_control,    /* see below */
  36.          fd_std_time,    /* standard time out value (XT only) */
  37.          fd_format_time,    /* time out for format drive (XT only) */
  38.          fd_check_time;    /* time out for check drive (XT only) */
  39.     word fd_lz;                /* landing zone */
  40.     char fd_sec_per_track;    /* # of sectors per track */
  41.     char fd_reserved;    /* reserved for future use */
  42. } DISK_TABLE, far *FDPTR;
  43.  
  44. struct program {
  45.     word init_jump;
  46.     DISK_TABLE fdtbld;
  47.     byte unused0[4];
  48.     word intr_no;
  49.     byte unused1[7];
  50.     word intr_off;
  51.     byte unsused2[3];
  52.     word intr_seg;
  53.     byte unsed3[8];
  54.     byte diskno;
  55.     byte unused4[11];
  56. } *data;
  57. #define p_ncyls        fdtbld.fd_ncyls
  58. #define p_heads        fdtbld.fd_heads
  59. #define p_current    fdtbld.fd_current
  60. #define p_precomp    fdtbld.fd_write_precomp
  61. #define p_burst        fdtbld.fd_ecc_burst
  62. #define p_control    fdtbld.fd_control
  63. #define p_stdtime    fdtbld.fd_std_time
  64. #define p_fmttime    fdtbld.fd_format_time
  65. #define p_chktime    fdtbld.fd_check_time
  66. #define p_lz        fdtbld.fd_lz
  67. #define p_sec_per_track    fdtbld.fd_sec_per_track
  68. #define p_reserved    fdtbld.fd_reserved
  69.  
  70. byte data_tbl[] = {
  71.     0xEB, 0x10,
  72.     0x00, 0x04, 0x04, 0x00, 0x00, 0xff, 0xff, 0x00,
  73.     0x00, 0x00,    0x00, 0x00, 0x00, 0x04,    0x11, 0x00,
  74.     0xBE, 0x02, 0x01, 0xBF,
  75.     0x90, 0x01,
  76.     0x33, 0xC9,    0x8E, 0xC1, 0x26, 0x89, 0x3E,
  77.     0x04, 0x01,
  78.     0x26, 0x89, 0x0E,
  79.     0x06, 0x01,
  80.     0xB9, 0x08, 0x00, 0xF3, 0xA5, 0xB4, 0x09, 0xB2,
  81.     0x80,
  82.     0xCD, 0x13, 0xB4, 0x00, 0xCD, 0x13, 0xB8, 0x00, 0x4C, 0xCD, 0x21
  83. };
  84.  
  85. #define DISK_NO1 0x80
  86. #define DISK_NO2 0x81
  87. #define DISK_NO1_LOC 0x41*4
  88. #define DISK_NO2_LOC 0x46*4
  89.  
  90. #define DFLT_INTR 0x64
  91.  
  92. char *prgname = "tblint .com";
  93.  
  94. main()
  95. {
  96.     int i, fd, line_no=4, num_disks;
  97.     union REGS regs;
  98.  
  99.     data = (struct program *)data_tbl;
  100.  
  101.     regs.h.ah = 8;
  102.     regs.h.dl = 0x80;
  103.     int86(0x13, ®s, ®s);
  104.     num_disks = regs.h.dl;
  105.  
  106.     scr_smode(scr_gmode());    /* clear screen */
  107.     scr_pos(22,0);
  108.     printf("Custom Fixed Disk Installation, Copyright(C) 1986, 1988 S. E. Garfinkle.");
  109.     scr_pos(23,0);
  110.     printf("All rights reserved.");
  111.     i = get_scr_val(line_no++,10,"Disk number 1 or 2?",1,1,2);
  112.     if (num_disks >= i)
  113.         data->fdtbld = *(FDPTR) _dos_getvect(i==1 ? 0x41 : 0x46);
  114.     prgname[6] = i+'0';
  115.     if (i == 1) {
  116.         data->diskno  = DISK_NO1;
  117.         data->intr_off = DISK_NO1_LOC;
  118.         data->intr_seg = DISK_NO1_LOC+2;
  119.         i = DFLT_INTR;
  120.     }
  121.     else {
  122.         data->diskno  = DISK_NO2;
  123.         data->intr_off = DISK_NO2_LOC;
  124.         data->intr_seg = DISK_NO2_LOC+2;
  125.         i = DFLT_INTR+4;
  126.     }
  127.     data->intr_no = 4 * get_scr_val(line_no++,16,"Use which base interrupt (base 16)? ",i,0x60,0x6c);
  128.     data->p_heads = get_scr_val(line_no++,10,"Number of heads on the disk?",data->p_heads,0,72);
  129.     data->fdtbld.fd_ncyls = get_scr_val(line_no++,10,"Number of cylinders (max 1024)?",data->fdtbld.fd_ncyls,20,1024);
  130.     data->p_control = get_scr_val(line_no++,16,"Control byte value (base 16)?",0,0,0xff);
  131.     i = get_scr_val(line_no++,10,"Are you using an AT (0) or XT (1) compatible?",0,0,1);
  132.     data->p_precomp = get_scr_val(line_no++,10,
  133.                   "Cylinder on which to start write precompensation?", i-1,-1,data->p_ncyls-1);
  134.     if(i) {
  135.         data->p_current = get_scr_val(line_no++,10,"Cylinder on which to start write reduced write current?",
  136.                             data->p_precomp,0,data->p_ncyls-1);
  137.         data->p_burst = get_scr_val(line_no++,10,"ECC Burst length?", 0x0b,0,0xff);
  138.         data->p_stdtime = get_scr_val(line_no++,10,"Standard timeout value?",0x0c,0,0xff);
  139.         data->p_fmttime = get_scr_val(line_no++,10,"Timeout value for formatting?",0xb4,0,0xff);
  140.         data->p_chktime = get_scr_val(line_no++,10,"Timeout value for checks?",0x28,0,0xff);
  141.     }
  142.     else {
  143.         data->p_lz = get_scr_val(line_no++,10,"Cylinder for landing zone?",data->p_ncyls,0,2048);
  144.         data->fdtbld.fd_sec_per_track = get_scr_val(line_no++,10,"Number of sector per track?",data->fdtbld.fd_sec_per_track,1,40);
  145.     }
  146.     if((fd=open(prgname,O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,S_IREAD|S_IWRITE)) < 0) {
  147.         fprintf(stderr,"\nCouldn't open file: '%s' ",prgname);
  148.         fputs(errno==EACCES ? "exists and is read-only or is a directory\n" :
  149.                               ". Couldn't open any more files (check config.sys)\n",
  150.               stderr);
  151.         exit(1);
  152.     }
  153.     write(fd,data_tbl,sizeof(struct program));
  154.     close(fd);
  155.     exit(0);
  156. }
  157.  
  158. #define ESC 27
  159. #define BACKSPACE 8
  160.  
  161. int
  162. get_scr_val(start, base, m_str, def_val, low_lim, high_lim)
  163. int start;        /* what line this goes on */
  164. char *m_str;    /* what to say on that line */
  165. int def_val,    /* default value */
  166.     low_lim,    /* least acceptable value */
  167.     high_lim;    /* highest acceptable value */
  168. {
  169.     int val, len, len1, len2, len3;
  170.     word pos, row, col, col2;
  171.     char buf[8];
  172.  
  173.     len1 = strlen(itoa(def_val, buf, base));
  174.     len2 = strlen(itoa(low_lim, buf, base));
  175.     len3 = strlen(itoa(high_lim, buf, base));
  176.     len = max(max(len1,len2),len3);
  177.     scr_pos(start,0);
  178.     printf("%s  [%*s]",m_str,len," ");
  179.     fflush(stdout);
  180.     pos = scr_rpos();    /* read scr_pos position */
  181.     row = pos >> 8;
  182.     col2 = (pos & 0xff) - 2;
  183.     col = col2-len+1;
  184. #ifdef DEBUG
  185.     scr_pos(24,0); printf("len %d, row %d, col2 %d",len,row,col2);
  186.     fflush(stdout);
  187. #endif
  188.     do {
  189.         int c;
  190.  
  191.         val = 0;
  192.         do {
  193.             scr_pos(row, col);
  194.             printf(base==10 ? "%*d" : "%*x",
  195.                 len,val ? val : def_val);
  196.             fflush(stdout);
  197.             scr_pos(row, col2);
  198.             c=getch();
  199.             if(isupper(c))
  200.                 c = tolower(c);
  201. #ifdef DEBUG
  202. scr_pos(18,0);printf("!! val %d, c %d\n",val,c);fflush(stdout);
  203. #endif
  204.             switch (c) {
  205.             case '0':
  206.             case '1':
  207.             case '2':
  208.             case '3':
  209.             case '4':
  210.             case '5':
  211.             case '6':
  212.             case '7':
  213.             case '8':
  214.             case '9':
  215.                 if((val = val*base + c - '0') > high_lim) {
  216.                     scr_pos(row+2,0);
  217.                 printf(base==10 ? "Maximum value is %d.":
  218.                       "Maximum value is %x.",high_lim);
  219.                     sleep(1000L);
  220.                     erase_eol(row+2);
  221.                     val = 0;
  222.                 }
  223.                 break;
  224.             case 'a':
  225.             case 'b':
  226.             case 'c':
  227.             case 'd':
  228.             case 'e':
  229.             case 'f':
  230.                 if(base==16 &&
  231.                    (val = val*base + c - 'a'+10) > high_lim) {
  232.                     scr_pos(row+2,0);
  233.                     printf("Maximum value is %x.",high_lim);
  234.                     sleep(1000L);
  235.                     erase_eol(row+2);
  236.                     val = 0;
  237.                 }
  238.                 break;
  239.             case BACKSPACE:
  240.                 if(val)
  241.                     val /= base;
  242.                 break;
  243.  
  244.             case EOF:
  245.                 exit(1);    /* assume we need an immediate abort */
  246.                 /* NOTREACHED */
  247.  
  248.             /* default: ignore the character. */
  249.  
  250.             } /* end of switch */
  251.         } while (c != '\r' && c != '\n' && c != ESC);
  252.         if(!val)
  253.             val = def_val;
  254.         else if (val<low_lim) {
  255.             scr_pos(row+2,0);
  256.             printf(base==10 ? "Minimum value is %d.":
  257.                   "Minimum value is %x.", low_lim);
  258.             sleep(1000L);
  259.             erase_eol(row+2);
  260.         }
  261.     } while(val<low_lim);
  262.     return(val);
  263. }
  264.  
  265. erase_eol(from)    /* erase line "from" and stay there */
  266. word from;
  267. {
  268.     word scr_gac();
  269.  
  270.     scr_scroll(from, 0, from, 79, 0, 7);
  271.     scr_pos(from,0);
  272. }
  273.  
  274. /*
  275. ; FDTBLINT:  Create fixed disk table to use instead of default DOS ones.
  276. ; This version  should normally only be used if you plan to use the IBM
  277. ; diagnostic routines -- these routines screw up the memory management and 
  278. ; overwrite the table of FDTBL.  See accompanying program FDTBL, otherwise.
  279. ;
  280.     .RADIX    16
  281. INTR